package com.suishoupai.xmb.exception;

/**
 * Created by caojian on 2017/4/12.
 */
public class XmbException extends IllegalAccessException {
    private String error;
    private int code;
    private static final int CODE_REPEAT_REQUEST = 1;
    private static final int CODE_ERROR = 2;
    private static final int CODE_NEED_VERIFICATION = 3;

    private XmbException(int code, String error) {
        super(error);
        this.code = code;
        this.error = error;
    }

    /**
     * new错误
     *
     * @param error
     * @return
     */
    public static XmbException newError(String error) {
        return new XmbException(CODE_ERROR, error);
    }

    /**
     * new验证码错误
     *
     * @param error
     * @return
     */
    public static XmbException newVerificationError(String error) {
        return new XmbException(CODE_NEED_VERIFICATION, error);
    }

    /**
     * new重复操作
     *
     * @return
     */
    public static XmbException newRepeatRequest() {
        return new XmbException(CODE_REPEAT_REQUEST, null);
    }

    public String getError() {
        return error;
    }

    /**
     * 重复操作
     *
     * @return
     */
    public boolean isRepeatRequest() {
        return code == CODE_REPEAT_REQUEST;
    }

    /**
     * 验证码错误
     *
     * @return
     */
    public boolean isVerification() {
        return code == CODE_NEED_VERIFICATION;
    }
}
